package cst.neu.yuejian_31.fragment;


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

import cst.neu.yuejian_31.R;
import cst.neu.yuejian_31.adapter.MasterVideoAdapter;
import cst.neu.yuejian_31.bean.MasterVideoBean;
import cst.neu.yuejian_31.iface.MasterVideoListener;
import cst.neu.yuejian_31.model.MasterVideoModel;

/**
 * A simple {@link Fragment} subclass.
 */
public class MasterVideoFragment extends BaseFragment implements MasterVideoListener {
    private RecyclerView recyclerView;
    private MasterVideoAdapter videoAdapter;
    private RecyclerView.LayoutManager layoutManager;
    private Context context;
    private List<MasterVideoBean> list;
    private View view;
    private String masterId;


    public MasterVideoFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view= inflater.inflate(R.layout.fragment_master_video, container, false);
        initView();
        iniData();
        return view;
    }

    private void iniData() {
        Intent intent=getActivity().getIntent();
        masterId=intent.getStringExtra("master_id");
        MasterVideoModel mastervideoModel=new MasterVideoModel();
        mastervideoModel.masterVideo(masterId,this);
    }

    private void initView() {
        context=getActivity();
        recyclerView= (RecyclerView) view.findViewById(R.id.recyclerView_mastervideo);
        layoutManager=new LinearLayoutManager(context);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setHasFixedSize(true);
        videoAdapter=new MasterVideoAdapter(context);
        videoAdapter.setList(list);
        recyclerView.setAdapter(videoAdapter);
// 设置Item之间间隔样式
        recyclerView .addItemDecoration(new DividerItemDecoration(context,LinearLayoutManager.VERTICAL));
    }


    @Override
    public void onSuccess(List<MasterVideoBean> videoBeen) {
        list=videoBeen;
        videoAdapter.setList(list);
    }

    @Override
    public void onFail(String msg) {

    }
}